package com.internetCafes.spms.web.customer.service.impl.role;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.internetCafes.spms.web.customer.entity.role.EntRoleInfo;
import com.internetCafes.spms.web.customer.mapper.role.EntRoleInfoMapper;
import com.internetCafes.spms.web.customer.model.role.*;
import com.internetCafes.spms.web.customer.service.role.IEntRoleInfoService;
import com.internetCafes.spms.web.sys.common.InitConst;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class EntRoleInfoServiceImpl extends ServiceImpl<EntRoleInfoMapper, EntRoleInfo> implements IEntRoleInfoService {


    @Override
    public List<Long> getBranchIdListByUserId(Long userId) {
        return baseMapper.getBranchIdListByUserId(userId);
    }

    @Override
    public Page<EntRoleInfoPo> pagingPo(Page<EntRoleInfo> page, EntRoleInfoDo roleInfoDo) {
        return baseMapper.pagingPo(page, roleInfoDo);
    }

    @Override
    public void initEntData(Long tenantId) {
        List<EntRoleInfo> roleListPo = baseMapper.listSysInitDate()
                .stream()
                .filter(po -> po.getTenantId().toString().equals(InitConst.SysTenantId.ROLE.getValue()))
                .collect(Collectors.toList());

        for (EntRoleInfo roleInfo : roleListPo) {
            roleInfo.setId(null);
            roleInfo.setTenantId(tenantId);
        }
        baseMapper.saveBatchSysInitDate(roleListPo);
    }

    @Override
    public List<RoleMenuPo> getUserMenuList(Long userId) {
        return baseMapper.getUserMenuList(userId);
    }

    @Override
    public List<EntRoleListPo> poList(EntRoleListDo listDo) {
        return baseMapper.poList(listDo);
    }

    @Override
    public EntRoleDetailPo getDetailById(Long id) {
        return baseMapper.getDetailById(id);
    }

    @Override
    public Page<EntRolePagingPo> paging(Page<EntRoleInfo> page, Wrapper<EntRoleInfo> queryWrapper) {
        return baseMapper.paging(page, queryWrapper);
    }
}
